﻿<?php $total = 0;?>

	<div class="menu-left">
			<h2>Categorias</h2>
				<ul>
		<?php if(isset($this->categorias)):?>
							<?PHP foreach ($this->categorias as $categoria): ?>
							<li><a href="<?PHP echo $this->url(array('module' => 'default', 'controller' => 'cardapio', 'action' => 'index', 'categoria' => $categoria['nome_categoria']), null, true); ?>"><?php echo $categoria['nome_categoria'];?></a></li>
							<?PHP endforeach; ?>
		<?php else:?>
					<li>Categoria 1</li>
					<li>Categoria 2</li>
					<li>Categoria 3</li>
					<li>Categoria 4</li>
					<li>Categoria 5</li>
					<li>Categoria 6</li>
					<li>Categoria 7</li>
					<li>Categoria 8</li>
		<?php endif;?>
				</ul>
		</div>
	
	<div class="conteudo">
	<h2>Carrinho</h2>
		<form id="ingredientes-form"  method="post" action="<?PHP echo $this->url(array('module' => 'default', 'controller' => 'carrinho','action' => 'finalizar'), null, true); ?>">
	<?PHP if (isset($this->produtos)): ?>
		<?PHP foreach ($this->produtos as $posicao => $id): ?>
			<div class="cart">
				<?PHP if (isset($this->ingredientes)): ?>
		<?php $estaticos = array();?>
		<div class="cartIngred">
			<div class="cartIngredDados">
				<div class="ing-adc">
				<h3>Ingredientes Custom: </h3>
				<table border="0">
					<?php foreach($this->ingredientes as $ingrediente):?>
						<?php for($i=0;$i<sizeof($ingrediente);$i++):?>
							<?php if($ingrediente[$i]['id_produto'] == $id):?>
								<?php 
									$busca = $ingrediente[$i]['id_ingrediente'];

										$ingredienteModel = new Application_Model_Ingrediente();
										$nome_ingred = $ingredienteModel->fetchAll(
											$ingredienteModel->select()
												->from($ingredienteModel->info(Zend_Db_Table_Abstract::NAME))
												->columns(array('nome_ingrediente'))
												->where('id_ingrediente = ?', $busca)
											);
								?>

					<?php if(($ingrediente[$i]['qtd_padrao'] == $ingrediente[$i]['qtd_max']) && ($ingrediente[$i]['qtd_padrao'] == $ingrediente[$i]['qtd_min'])):?>
						<?php $estaticos[] = $nome_ingred[0]['nome_ingrediente'];?>
					<?php else:?>
					<tr>
					<td width = "50%">
						<!--<input type="checkbox" name="<?php echo $posicao; ?>-<?php echo $ingrediente[$i]['id_ingrediente'];?>" checked value="1"/>-->
					<?php echo $nome_ingred[0]['nome_ingrediente'];?> 
					</td>
					<td >
							<select name="q-<?php echo $posicao; ?>-<?php echo $ingrediente[$i]['id_ingrediente'];?>">
							<?php for($j=$ingrediente[$i]['qtd_min'];$j<=$ingrediente[$i]['qtd_max'];$j++):?>
							<option
							<?php if($j == $ingrediente[$i]['qtd_padrao']){echo 'selected';}?>
							><?php echo $j;?></option>
							<?php endfor;?>
							</select>
							<?php if($ingrediente[$i]['valor'] != 0):?>
								Adic: <?PHP echo 'R$ ' . number_format($ingrediente[$i]['valor'] / 100, 2, ',', '.');?>
							<?php endif;?>
					</td>
				</tr>
				<?php endif;?>
				<?php endif;?>
			<?php endfor;?>
		<?php endforeach;?>
		
		</table>
		</div>
		
		<div class="ing-padrao">
		<h3>Ingredientes Fixos: </h3>
			<?php foreach($estaticos as $chave => $valor):?>
						<?php echo $valor;?>
						<?php if($chave == (sizeof($estaticos)-1)):?>
						<?php echo '.';?>
						<?php else:?>
						<?php echo ',';?>
						<?php endif;?>
					<?php endforeach;?>
		</div>			
</div>
</div>
	<?php endif;?>
				<?php 
					$busca = $id;

					$produtoModel = new Application_Model_Produto();
						$nome_produto = $produtoModel->fetchAll(
											$produtoModel->select()
												->from($produtoModel->info(Zend_Db_Table_Abstract::NAME))
												->columns(array('nome','preco'))
												->where('id_produto = ?', $busca)
											);
				?>
				<div class="cartInfo">
					<img width="136" height="107" src="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/img/produtos/'. $id . '.jpg'; ?>"/>
					<h4><?php echo $nome_produto[0]['nome'];?></h4>
					<h4><?PHP echo 'R$ ' . number_format($nome_produto[0]['preco'] / 100, 2, ',', '.');?></h4>
					<h4><a href="<?PHP echo $this->url(array('action' => 'remover', 'id' => $posicao)); ?>">Excluir Produto</a></h4>
					<?php $total += $nome_produto[0]['preco'];?>
				</div>
			</div>
		<?PHP endforeach; ?>
	<h3 style="text-align: left; color: green;">Total: <?PHP echo 'R$ ' . number_format($total / 100, 2, ',', '.');?> + adicionais</h3>
		<div class="menus-cardapio">
			<?php if(Misc::isAdmin()):?>
			<?php else:?>
			<ul>
				<li class="button-admin">
					<input style=" background:none; border:none; text-align: center;" type="submit" value="Finalizar Compra"/>
				</li>
			</ul>	
			<?php endif; ?>
		</div>	
	</form>
	<?php else:?>
	<h3 style="text-align: center; color: red;">Você não possui ítens no carrinho!</h3>
	<?PHP endif; ?>    
</div>
